/**
  @creator: cilang
  @qq: 1019383856
  @bili: https://space.bilibili.com/433915419
  @gitee: https://gitee.com/OpencvLZG
  @github: https://github.com/OpencvLZG
  @since: 2023/11/26
  @desc: //TODO
**/

package dao

import (
	"errors"
	"ginFlutterBolg/internal/model"
	"ginFlutterBolg/internal/util"
)

type (
	UserFriendDao struct {
	}
)

// FriendUser 关注用户
func (u *UserFriendDao) FriendUser(userFriend *model.UserFriend) error {
	orm := util.Orm
	_, err := orm.InsertOne(userFriend)
	return err
}
func (u *UserFriendDao) QueryHasFriend(userFriend *model.UserFriend) (bool, error) {
	orm := util.Orm
	res, err := orm.Where("friend_id = ?", userFriend.FriendId).Get(userFriend)
	if err != nil {
		return res, err
	}
	return res, err
}

// GetFriendLimitOffset 用户关注列表
func (u *UserFriendDao) GetFriendLimitOffset(page int, userId int64) (*[]model.UserFriend, error) {
	orm := util.Orm
	userFriendList := make([]model.UserFriend, 0)
	err := orm.Where("user_id = ?", userId).Limit(10, page*10).OrderBy("create_time").Find(&userFriendList)
	if err != nil {
		return &userFriendList, errors.New("搜索用户列表错误，数据库搜索错误")
	}
	return &userFriendList, err

}
